package com.lemon.exam.common.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * 自定义 权限处理器
 *
 * @author Lemon
 * @since 2025/11/1 14:51
 */
@Slf4j
@Component
public class PermissionEvaluatorHandler implements PermissionEvaluator {
    @Override
    public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
        log.info("权限检查 - 用户: {}, 目标: {}, 权限: {}", authentication != null ? authentication.getName() : "null", targetDomainObject, permission);
        /**
         * @TODO
         * 自定义权限检查逻辑
         * 目前仅返回 true
         */
        return true;
    }

    @Override
    public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission) {
        log.info("类型权限检查 - 用户: {}, 目标类型: {}, 目标ID: {}, 权限: {}", authentication != null ? authentication.getName() : "null", targetType, targetId, permission);
        /**
         * @TODO
         * 自定义权限检查逻辑
         * 目前仅返回 true
         */
        return true;
    }
}
